package com.zx.tradeclient.app;

import java.util.ArrayList;
import java.util.List;

import android.app.Application;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.provider.Settings.Secure;
import android.telephony.TelephonyManager;

import com.zx.base.lazylist.ImageLoader;
import com.zx.base.util.URLHelper;
import com.zx.tradeclient.ctrl.index1.Navigation;
import com.zx.tradeclient.entity.CategoryInfo;
import com.zx.tradeclient.entity.GoodsInfo;
import com.zx.tradeclient.entity.UserInfo;

public class TradeApp extends Application {

	public UserInfo user = new UserInfo();
	private List<Navigation> navs = null;

	public ArrayList<CategoryInfo> mCateg = new ArrayList<CategoryInfo>();
	public ArrayList<CategoryInfo> mArea = new ArrayList<CategoryInfo>();

	public CategoryInfo product_rating = new CategoryInfo();

	public String[] provinces;
	public String[][] citys;
	public String[][] cityids;
	public String[] productgroup;
	public String[][] producttypes;
	public String[][] typeids;
	public String[] tradeways;
	public String[] tradewaysid;
	public String[] ordertypes;
	public String[] ordertypesid;
	public int companySlideCount;
	public int productSlideCount;

	public ArrayList<GoodsInfo> mGoodInfo = new ArrayList<GoodsInfo>();

	public int categ_index = -1;

	public List<Navigation> getNavs() {
		return navs;
	}

	public void setNavs(List<Navigation> navs) {
		this.navs = navs;
	}

	public ImageLoader imageLoader;

	public boolean isNetWorkConnection = false;

	@Override
	public void onCreate() {
		super.onCreate();
		if (isPad()) {
			URLHelper.mPrefix = URLHelper.main + "/mobilepad.do";
		} else {
			URLHelper.mPrefix = URLHelper.main + "/mobile.do";
		}
		imageLoader= new ImageLoader(this);
	}
	
	private String phonetype = "";

	public String getPhoneType() {
		try {
			phonetype = android.os.Build.MODEL;
		} catch (Exception e) {
			// 获得手机型号
			phonetype = "无法获取型号";
		}
		return phonetype;
	}

	// IMEI
	private String imei = "";

	public String getImei() {
		try {
			if (imei.equals("")) {
				TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
				imei = tm.getDeviceId();
			}
		} catch (Exception e) {

		}

		return imei;
	}

	// IMSI
	private String imsi = "";

	public String getImsi() {
		try {
			if (imsi.equals("")) {

				// 判断当前是否是平板设备

				if (isPad()) {
					imsi = Secure.getString(this.getContentResolver(), Secure.ANDROID_ID);
				} else {
					imsi = ((TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE)).getSubscriberId();
				}

			}
		} catch (Exception e) {
			imsi = "";
			e.printStackTrace();
		}

		return imsi;
	}

	private String phone = "";

	public String getPhone() {
		try {
			if (phone.equals("")) {

				// 判断当前是否是平板设备

				if (isPad()) {
					phone = "";
				} else {
					phone = ((TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number();
				}

			}
		} catch (Exception e) {
			phone = "";
			e.printStackTrace();
		}

		return phone;
	}

	public boolean isPad() {
		TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
		int type = tm.getPhoneType();

		// 判断当前是否是平板设备
		if (type == TelephonyManager.PHONE_TYPE_NONE) {
			return true;
		} else {
			return false;
		}
	}

	// Version
	private String version = "";

	public String getVersion() {
		if (version.equals("")) {
			try {
				PackageManager packageManager = getPackageManager();
				PackageInfo packInfo = packageManager.getPackageInfo(getPackageName(), 0);
				version = packInfo.versionName;
			} catch (Exception e) {
			}
		}
		return version;
	}
}
